from flask import Blueprint, jsonify, request
from app.services.cabin_service import CabinService

def init_cabin_routes(ros_utils):
    cabin_bp = Blueprint('cabin', __name__)
    cabin_service = CabinService(ros_utils)
    
    @cabin_bp.route('/process', methods=['GET'])  # 完整路径: /api/cabin/process
    def cabin_process():
        result = cabin_service.process()
        return jsonify(result), result["code"]

    @cabin_bp.route('/emergency', methods=['POST'])
    def cabin_emergency():
        data = request.get_json()
        if not data or 'status' not in data:
            return jsonify({
                "code": 400,
                "message": "缺少status参数",
                "data": None
            }), 200
        
        status = data['status']
        result = cabin_service.emergency(status)
        return jsonify(result), result["code"]
    
    @cabin_bp.route('/setplum', methods=['POST'])
    def cabin_setPlum():
        data = request.get_json()
        if not data or 'status' not in data:
            return jsonify({
                "code": 400,
                "message": "缺少status参数",
                "data": None
            }), 200
        
        status = int(data['status'])
        result = cabin_service.setPlum(status)
        return jsonify(result), result["code"]
    
    return cabin_bp